import { defineStore } from "pinia";
import { ref } from "vue";
interface Book {
  id: number;
  title: string;
}
interface Books {
  name: string;
  id: number;
  picture: string;
  simple: string;
  author: string;
  type: string;
  createTime: string;
  newChapter: string;
  status: string;
  updateTime: string;
}
export const useBooksStore = defineStore(
  "books",
  () => {
    const bookID = ref<number>(0);
    const booksList = ref<Array<Book>>([]);
    const setBooksList = (books: Array<Book>) => {
      booksList.value = books;
    };
    const setBookId = (id: number) => {
      bookID.value = id;
    };
    // 当前章节
    const currentChapter = ref<number>(0);
    const setCurrentChapter = (chapter: number) => {
      currentChapter.value = chapter;
    };

    const booksDetail = ref<Books>({
      name: "",
      id: 0,
      picture: "",
      simple: "",
      author: "",
      type: "",
      createTime: "",
      newChapter: "",
      status: "",
      updateTime: "",
    });
    const setBooksDetail = (book: Books) => {
      booksDetail.value = book;
    };
    return {
      booksList,
      setBooksList,
      bookID,
      setBookId,
      booksDetail,
      setBooksDetail,
      currentChapter,
      setCurrentChapter,
    };
  },
  {
    persist: true,
  },
);

export default useBooksStore;
